473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

php help prepared statement

Hi

I have been fighting with this bit of code for two days I just can't get it to work properly, i am reading a set of words that hav been taking from a web page and stored in an array, I am now trying to do an analysis on the words from a database. So i want to incrementally read in each word from the array into a select query

Which i can do easily enough using this piece of code


[PHP]public function checkwords()
{
$db = new dbWork();

$array = split(';',file_get_contents("text.txt"));
foreach($array as $word)
{
$db->dbRead($word);

}
unset($word);


}
[/PHP]

but i don't think the php is getting the result from mysql properly as it never seems to find any matches in the database, which for testing purposes does exist. The faulty code is below


[PHP]//Calls database manager class and will pass values to database
public function dbRead($word)
{ $dbm = new dbm();
$dbm->openConn();



$stmt = $dbm->prep("SELECT count(*) FROM test tab where tab.words=?");
$stmt->bind_param('s',$word);
$stmt->execute();
$stmt->bind_result($bool);
$stmt->fetch();
$stmt->close();
$dbm->closeConn();

if($bool !=0)
{

//Reject Word
echo $solWord= 0;
}
else
{

//Accept word
echo $solWord=1;
}
} [/PHP]
Jan 10 '08 #1
1 1582
dlite922
1,584 Expert 1GB
Hi

I have been fighting with this bit of code for two days I just can't get it to work properly, i am reading a set of words that hav been taking from a web page and stored in an array, I am now trying to do an analysis on the words from a database. So i want to incrementally read in each word from the array into a select query

Which i can do easily enough using this piece of code


[PHP]public function checkwords()
{
$db = new dbWork();

$array = split(';',file_get_contents("text.txt"));
foreach($array as $word)
{
$db->dbRead($word);

}
unset($word);


}
[/PHP]

but i don't think the php is getting the result from mysql properly as it never seems to find any matches in the database, which for testing purposes does exist. The faulty code is below


[PHP]//Calls database manager class and will pass values to database
public function dbRead($word)
{ $dbm = new dbm();
$dbm->openConn();



$stmt = $dbm->prep("SELECT count(*) FROM test tab where tab.words=?");
$stmt->bind_param('s',$word);
$stmt->execute();
$stmt->bind_result($bool);
$stmt->fetch();
$stmt->close();
$dbm->closeConn();

if($bool !=0)
{

//Reject Word
echo $solWord= 0;
}
else
{

//Accept word
echo $solWord=1;
}
} [/PHP]
you may have a SQL error:

print your SQL statement to the screen with die($sql_statement); and pasted into the database terminal/command line to see if its successful.

shouldn't the table name have a comma between them like this:

Expand|Select|Wrap|Line Numbers
  1. /*    
  2.       INSERT COMMA HERE \|/                 /*
  3. SELECT count(*) FROM test, tab WHERE... 
  4.  
Jan 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark | last post by:
hello! mysqli in PHP5 comes with prepared statements functionality. However, without persistent connections or connection pooling in this code library, one has to ask: why bother? are...
0
by: David.Tymon | last post by:
>Description: MySQL v4.1.0-alpha only allows a client to prepare a maximum of 254 statements. On the 255th mysql_prepare() call, a failure is returned with no information returned by...
1
by: Tom D | last post by:
I'm rewriting a database interface that our company currently has. Currently it's using the Pear::DB interface, but we found that that was introducing a bit too much overhead. I'm rewriting the...
0
by: Prashanth | last post by:
I am getting this error from BEA DB2 Driver in weblogic console. java.sql.SQLException: CURSOR C02 NOT IN A PREPARED STATE java.sql.SQLException: CURSOR C02 NOT IN A PREPARED STATE We keep...
2
by: Cyril VELTER | last post by:
I'm converting an application to use the V3 protocol features in the 7.4 libpq. As I need to make a design choice regarding the use of prepared statements, I'm wondering what ressources does a...
3
by: birju | last post by:
Hi, I'm running SQL Profiler on an SQL Server 2000 database. I see that one stored procedure gets repeatedly executed having a handle of '1'. This query takes a long time to complete. How do I...
2
by: toomanyjoes | last post by:
I have written a function that runs a prepared statement and it seems to run just fine but when I check to see the affected rows nothing is affected. Can someone take a look at my code and tell me...
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
1
by: kaushikm | last post by:
How to access sql server inbuilt functions from java prepared statement ? I have used getdate() of sql in a java prepared statement and am connecting to sqlserver. But it's not working. What to do ?
4
by: TechieGrl | last post by:
Prepared statements are new to me and having to do this with a multi- dimensional array is beyond me. Here is the prepared statement block: // Prepare to insert a record into table1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.