Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > I hate bugs...Mysqli issue
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 2nd November 10:18
japruim
External User
 
Posts: 1
Default I hate bugs...Mysqli issue



Hi everyone.

I have a script that I've been using succesfully for quite awhile, and
just today found a bug...

I attempted to insert a new record into the database and got this
error in my error log:

[Fri Dec 21 11:08:43 2007] [error] PHP Warning:
mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt,
boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on
line 31
[Fri Dec 21 11:08:43 2007] [error] PHP Warning: mysqli_stmt_execute()
expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/
RAIDer/webserver/Documents/OLDB/add.php on line 33
[Fri Dec 21 11:08:43 2007] [error] PHP Warning:
mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt,
boolean given in /Volumes/RAIDer/webserver/Documents/OLDB/add.php on
line 35
[Fri Dec 21 11:08:43 2007] [error] PHP Warning: mysqli_stmt_close()
expects parameter 1 to be mysqli_stmt, boolean given in /Volumes/
RAIDer/webserver/Documents/OLDB/add.php on line 41

And those lines from my script are:

//Create the statement
$stmt = mysqli_prepare($link, "INSERT INTO current VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssssssss', $FName, $LName, $Add1,
$Add2, $City, $State, $Zip, $XCode, $Record);
//Add the record
mysqli_stmt_execute($stmt);

printf("%d Row Inserted.\n", mysqli_stmt_affected_rows($stmt));

// Redirect back to index.php for viewing
//header("Location: index.php");

//Close the statement
mysqli_stmt_close($stmt);

?>

The $stmt is line 30 only thing above it is mapping the post info to
the field names to be inserted.

With my limited knowledge of mysqli functions, it could be the
issue... But what I don't get is why this bug is rearring it's head
now... When I'm supposed to go on vacation for a few weeks...

Any help would be greatly appreciated.

The basics of what I used was copied directly from the php.net site.
so I'm very confused...


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
japruim@raoset.com
  Reply With Quote


 


2 2nd November 10:18
znemeth
External User
 
Posts: 1
Default I hate bugs...Mysqli issue



2007. 12. 21, péntek keltezéssel 11.14-kor Jason Pruim ezt Ã*rta:


an error must have occurred with mysqli_prepare, so it returned a
boolean false, that's what all those warnings are complaining about...

are you sure $link is a valid mysqli link identifier?

greets
Zoltán Németh
  Reply With Quote
3 2nd November 10:19
japruim
External User
 
Posts: 1
Default I hate bugs...Mysqli issue


Here is where I connect to the database:

<?php

$link = mysqli_connect($server, $username, $password, $database) ;

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit(); }
?>
It looks valid to me... as long as it's connecting... the username/
password/database are all correct, I can log in from the command line
with no issue....

--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
japruim@raoset.com
  Reply With Quote
4 2nd November 10:19
znemeth
External User
 
Posts: 1
Default I hate bugs...Mysqli issue


2007. 12. 21, péntek keltezéssel 11.50-kor Jason Pruim ezt Ã*rta:


try a var_dump on $link and on $stmt after the mysqli_prepare and see
what it shows
greets Zoltán Németh
  Reply With Quote
5 2nd November 10:19
japruim
External User
 
Posts: 1
Default I hate bugs...Mysqli issue


Hey Zoltan,

Thanks for looking, here's the result of the vardump, I did $link
first and then $stmt

object(mysqli)#1 (0) { } bool(false)

Not quite what it should be is it?

--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
japruim@raoset.com
  Reply With Quote
6 3rd November 01:53
gmane
External User
 
Posts: 1
Default I hate bugs...Mysqli issue


And as a general rule, defensive programming approaches would state that
you should check all the return values before blindly using them.... in
fact that's not really defensive specifically, just GPP

Col.
  Reply With Quote
7 3rd November 01:53
gmane
External User
 
Posts: 1
Default I hate bugs...Mysqli issue


Well the first bit looks fine but clearly the mysqli_prepare() is not
working properly. Try calling mysqli_error() to see what the problem is.

Col

PS please try to strip more of the fluff from the quoted mails as it
makes it much quicker/easier to read the thread (context is good but we
don't need multiple copies of signatures etc.
  Reply With Quote
8 3rd November 01:54
znemeth
External User
 
Posts: 1
Default I hate bugs...Mysqli issue


2007. 12. 21, péntek keltezéssel 12.04-kor Jason Pruim ezt Ã*rta:


surely not
if this is the result for var_dump($link) then the connection fails. try
mysqli_connect_error() to see what is breaking.

greets
Zoltán Németh
  Reply With Quote
9 4th November 10:03
ceo
External User
 
Posts: 1
Default I hate bugs...Mysqli issue


Perhaps it is valid, when the database is up and running.

But if your DB was re-started for some reason, the link won't be there
while it's restarting will it?

You've GOT to write code to handle the $link being false instead of
marching blindly off the cliff.

You are not a lemming. :-)

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?
  Reply With Quote
Reply


Thread Tools
Display Modes




666