# unexpected '{' in bind\_parm statement

**URL:** <https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307>\
**Category:** MySQL database\
**Created:** [September 2, 2014, 2:51pm UTC](https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307 "2014-09-02T14:51:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![usit](https://www.phphelp.com/letter_avatar_proxy/v4/letter/u/ee7513/32.png) [@usit](https://www.phphelp.com/u/usit)\
**Post date:** [September 2, 2014, 2:51pm UTC](https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307/1 "2014-09-02T14:51:57Z")

</div>

Some help needed (again!)  
unexpected ‘{’ in bind\_param statement.

[php] include\_once ($\_SERVER[‘DOCUMENT\_ROOT’] . ‘/cgi-bin/cnnct2mysqli.php’);

```
$mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName); //this sequence req'd

if ($mysqli_connect_errno) {
	echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
	}

```

If(!file\_exists(‘test5’))

```
$sql="CREATE TABLE test5(
	 `id` INTEGER(6) UNSIGNED NOT NULL AUTO_INCREMENT,
	 `amount` char(6) DEFAULT NULL,
	 `item_name` char(10) DEFAULT NULL,
	 `email` char(40) DEFAULT NULL,
	 `first_name` char(20),
	 `last_name` char(40),
	 `address1` char(100) DEFAULT NULL,
	 `address2` char(100) DEFAULT NULL,
	 `city` char(50) DEFAULT NULL,
	 `state` char(6) DEFAULT NULL,
	 `country` char(6) DEFAULT NULL,	
	 `zip` char(12) DEFAULT NULL,
	 `mc_gross` char(6) DEFAULT NULL,
	 `mc_fee` char(6) DEFAULT NULL,
	 `tax` char(6) DEFAULT NULL,
	 `invoiceNo` char(20) DEFAULT NULL,
	 `payment_date` char(20) DEFAULT NULL,
	 `s_h` char(6) DEFAULT NULL,
	 `affiliation` char(40) DEFAULT NULL,
	 `e_anncmnt` char(10) DEFAULT NULL,
	 `hit` varchar(100) DEFAULT NULL,
	 `USIT_txt` char(5) DEFAULT FALSE,
	 `quantity` char(5) DEFAULT FALSE,
	 `updated` DATE,
	 `created` DATE,
	 PRIMARY KEY (invoiceNO),
	 INDEX (id)
)";

$amount = 0.50; //d
$item_name	= 'bk'; //s
$email = 'nk@u-sit.net'; //s
$first_name	= 'Fname'; //s
$last_name = 'LongerLastNames';	//s
$address1 = 'Addr01'; //s
$address2 = 'Addr02'; //s
$city = 'cty'; //s
$state = 'MI'; //s
$country = 'US'; //s
$zip = 48138; //i
$mc_gross	= 0.00; //d
$mc_fee = 0.00; //d
$tax = 0.00; //d
$invoiceNo	= 140630; //i
$payment_date	= 'yyyy-mm-dd';//s
$s_h = 0.00; //d
$affiliation	= 'retired'; //s
$e_anncmnt	= true; //s
$hit = 123; //i
$USIT_txt	= 'true'; //s
$quantity = 1; //i 22 vars to here
$updated	= ''; //s
$created	= ''; //s

```

$stmt = $mysqli-\>prepare(“INSERT INTO test5 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)”)  
{ //L. 70 \<-- syntax error, unexpected ‘{’ … line 70  
$stmt-\>bind\_param(“dsssssssssidddisdssisiss”,`$amount`,`$item_name`,`$email`,`$first_name`,`$last_name`,`$address1`,`$address2`,`$city`,`$state`,`$country`,`$zip`,`$mc_gross`,`$mc_fee`,`$tax`,`$invoiceNo`,`$payment_date`,`$s_h`,`$affiliation`,`$e_anncmnt`,`$hit`,`$USIT_txt`,`$quantity`,`updated`,`created`);  
$stmt-\>execute();   
$stmt-\>bind\_result(test5);  
$stmt-\>close();  
}

exit;[/php]

Any insights appreciated  
usit

---

<div class="post-metadata">

**Author:** ![fastsol](https://www.phphelp.com/user_avatar/www.phphelp.com/fastsol/32/374_2.png) [@fastsol](https://www.phphelp.com/u/fastsol)\
**Post date:** [September 2, 2014, 3:47pm UTC](https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307/2 "2014-09-02T15:47:00Z")

</div>

Ummm, what the heck are you trying to do with that bindParam()? You can’t just place all the vars in one bind statement. The bind only takes one param at a time.  
RTFM! [http://php.net/manual/en/pdostatement.bindparam.php](http://php.net/manual/en/pdostatement.bindparam.php)

---

<div class="post-metadata">

**Author:** ![usit](https://www.phphelp.com/letter_avatar_proxy/v4/letter/u/ee7513/32.png) [@usit](https://www.phphelp.com/u/usit)\
**Post date:** [September 2, 2014, 6:07pm UTC](https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307/3 "2014-09-02T18:07:14Z")

</div>

I’m trying to follow thd mysqli manual; in particular the bind\_param() function at …  
[http://php.net/manual/en/mysqli-stmt.bind\_param.php](http://php.net/manual/en/mysqli-stmt.bind_param.php)  
It gives an example of bind\_param() with 4 parameters, as shown here …

$stmt-\>bind\_param(‘sssd’, $code, $language, $official, $percent);

I have not run across any limitations on the number of parameters prmitted.

usit

---

<div class="post-metadata">

**Author:** ![fastsol](https://www.phphelp.com/user_avatar/www.phphelp.com/fastsol/32/374_2.png) [@fastsol](https://www.phphelp.com/u/fastsol)\
**Post date:** [September 2, 2014, 7:47pm UTC](https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307/4 "2014-09-02T19:47:15Z")

</div>

The limitation IS what the manual shows. Plus the params are not just random things, they are very specific things based on what you want the bind to do. You have 25 params in your statement. If you need to bind each var that is being sent to the db then you can use a foreach() to do that, just like the user provided examples show.

---

<div class="post-metadata">

**Author:** ![usit](https://www.phphelp.com/letter_avatar_proxy/v4/letter/u/ee7513/32.png) [@usit](https://www.phphelp.com/u/usit)\
**Post date:** [September 4, 2014, 2:37pm UTC](https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307/5 "2014-09-04T14:37:39Z")

</div>

Got through the unexpected ‘{’ and then started over. (Should this be a new topic?)

What am I trying to do? Trying to create a db, insert into it, then select from it using mysqli – and learn a little mysqli in the process.  
Here, I’m using an example oo script from [http://php.net/manual/en/mysqli-stmt.bind-param.php](http://php.net/manual/en/mysqli-stmt.bind-param.php).

At this point, I’m confused by the meaning of ‘bind\_param()’. I have yet to find an explanation of what ‘bind’ means, the limits on the number of parameters, and why a limit.

The latest script throws the error: ‘Call to a member function bind\_param() on a non-object’.

[php]// creaTbl\_test5b.php  
// Refs: [http://php.net/manual/en/mysqli-stmt.bind-param.php](http://php.net/manual/en/mysqli-stmt.bind-param.php)

```
include_once ($_SERVER['DOCUMENT_ROOT'] . '/cgi-bin/cnnct2mysqli.php');

$mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName); //this sequence req'd

if ($mysqli_connect_errno) {
	echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
	}

```

If(!file\_exists(test5))

```
$sql="CREATE TABLE test5(
	 `id` INTEGER(6) UNSIGNED NOT NULL AUTO_INCREMENT,
	 `amount` char(6) DEFAULT NULL,
	 `item_name` char(10) DEFAULT NULL,
	 `email` char(40) DEFAULT NULL,
	 `first_name` char(20),
	 PRIMARY KEY (invoiceNO),
	 INDEX (id)
)";

$amount = 1.00; //d
$item_name	= 'book'; //s
$email = 'ntelleck@u-sit.net'; //s
$first_name	= 'Fname'; //s

```

$stmt=$mysqli-\>prepare(“INSERT INTO test5 VALUES (?,?,?,?)”);

$stmt-\>bind\_param(“dsss”,`$amount`,`$item_name`,`$email`,`$first_name`);

$stmt-\>execute();

printf("%d Row inserted.\n", $stmt-\>affected\_rows);

$mysqli-\>close();  
exit;[/php]

The last time I encountered this error mssg I think there was a discrepancy between the number of '?'s in the prepare statement and the number of params being passed in bind\_param(). Here I have 4 and 4 as in the example.

Is there any free software debugger program that can test this script?

Any suggestions appreciated  
usit

---

<div class="post-metadata">

**Author:** ![fastsol](https://www.phphelp.com/user_avatar/www.phphelp.com/fastsol/32/374_2.png) [@fastsol](https://www.phphelp.com/u/fastsol)\
**Post date:** [September 4, 2014, 3:59pm UTC](https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307/6 "2014-09-04T15:59:52Z")

</div>

Ahhh, I see, I was thinking of the PDO version bind\_param. The mysqli does allow for more params. The reason yours is failing is most likely cause you have `backticks` around the vars in the bind\_param(), you don’t need anything around them if you are passing vars and not a direct string. If you did a direct string then you would use ‘single’ quotes around those values.

The bind basically means that the system is binding the value supplied to a certain argument in the prepare query and then making it safe to put in the db by sanitizing it with the type you specified.

Also, this $mysqli\_connect\_errno won’t ever exist cause you are using the OOP method.

---

<div class="post-metadata">

**Author:** ![usit](https://www.phphelp.com/letter_avatar_proxy/v4/letter/u/ee7513/32.png) [@usit](https://www.phphelp.com/u/usit)\
**Post date:** [September 5, 2014, 1:27pm UTC](https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307/7 "2014-09-05T13:27:14Z")

</div>

FOUND errors and corrected them. Then decided to start over. Here’s the script I’m beginning with  
[php]  
//Example #1 Object oriented style found at [http://php.net/manual/en/mysqli-stmt.bind-param.php](http://php.net/manual/en/mysqli-stmt.bind-param.php)

$mysqli = new mysqli(‘localhost’, ‘my\_user’, ‘my\_password’, ‘world’);

/\* check connection \*/  
if (mysqli\_connect\_errno()) {  
printf(“Connect failed: %s\n”, mysqli\_connect\_error());  
exit();  
}

$stmt = $mysqli-\>prepare(“INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)”);  
$stmt-\>bind\_param(‘sssd’, $code, $language, $official, $percent);

$code = ‘DEU’;  
$language = ‘Bavarian’;  
$official = “F”;  
$percent = 11.2;

/\* execute prepared statement \*/  
$stmt-\>execute();

printf("%d Row inserted.\n", $stmt-\>affected\_rows);

/\* close statement and connection \*/  
$stmt-\>close();

/\* Clean up table CountryLanguage \*/  
$mysqli-\>query(“DELETE FROM CountryLanguage WHERE Language=‘Bavarian’”);  
printf("%d Row deleted.\n", $mysqli-\>affected\_rows);

/\* close connection \*/  
$mysqli-\>close();[/php]  
"The above example will output:

1 Row inserted.  
1 Row deleted.

=========

To this I added my DB credentials and a snipped to create the needed table. Here’s my new start:  
[php] include\_once ($\_SERVER[‘DOCUMENT\_ROOT’] . ‘/cgi-bin/cnnct2mysqli.php’);

$mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName);

/\* check connection \*/  
if (mysqli\_connect\_errno()) {  
printf(“Connect failed: %s\n”, mysqli\_connect\_error());  
exit();  
}

If(!file\_exists(test5))  
$sql=“CREATE TABLE test5(  
`id` INTEGER(6) UNSIGNED NOT NULL AUTO\_INCREMENT,  
`code` char(6) DEFAULT NULL,  
`language` char(10) DEFAULT NULL,  
`official` char(40) DEFAULT NULL,  
`percent` integer(20),  
PRIMARY KEY (code),  
INDEX (id)  
)”;

$stmt = $mysqli-\>prepare(“INSERT INTO test5 VALUES (?, ?, ?, ?)”);  
$stmt-\>bind\_param(‘sssd’, $code, $language, $official, $percent);

$code = ‘DEU’;  
$language = ‘Bavarian’;  
$official = “F”;  
$percent = 11.2;

/\* execute prepared statement \*/  
$stmt-\>execute($stmt);

printf("%d Row inserted.\n", mysqli\_stmt\_affected\_rows($stmt));

/\* close statement and connection \*/  
$stmnt-\>close();

/\* Clean up table test5 \*/  
$mysqli\_query(“DELETE FROM test5 WHERE Language=‘Bavarian’”);  
printf("%d Row deleted.\n", mysqli\_affected\_rows($link));

/\* close connection \*/  
$mysqli-\>close();[/php]

The compiler doesn’t like this script:  
“Call to a member function bind\_param() on a non-object”

Stuck again! I’ve tried to find the error. It’s possibly a type, but I can’t find it.

Help appreciated.

usit

---

<div class="post-metadata">

**Author:** ![usit](https://www.phphelp.com/letter_avatar_proxy/v4/letter/u/ee7513/32.png) [@usit](https://www.phphelp.com/u/usit)\
**Post date:** [September 10, 2014, 2:13pm UTC](https://www.phphelp.com/t/unexpected-in-bind-parm-statement/23307/8 "2014-09-10T14:13:16Z")

</div>

OK, fount it! (after 4 days of now power then a false virus attack). Code now modified to the following …

[php][//testCreatInsrtBindExec.php](https://testCreatInsrtBindExec.php)

include\_once ($\_SERVER[‘DOCUMENT\_ROOT’] . ‘/cgi-bin/cnnct2mysqli.php’);  
$mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName );

if ($mysqli-\>connect\_errno) {  
echo “Failed to connect to MySQL: (” . $mysqli-\>connect\_errno . ") " . $mysqli-\>connect\_error;  
}

$FistName = “Bavarian”; //s  
$LastName = “F”; //s  
$Age = 13; //d

$stmt = $mysqli-\>prepare(“INSERT INTO test5 VALUES (?, ?, ?)”);

$stmt-\>bind\_param(‘ssd’, $FirstName, $LastName, $Age);

$stmt-\>execute();

if ($result = $mysqli-\>query(“SELECT \* FROM test5”, MYSQLI\_USE\_RESULT)) {  
printf(“Select returned %d rows.\n”, $result-\>num\_rows);  
}//Select returned 0 rows. (Why?, test5 contains 5 col: one row has | NULL | F |11 |, others are similar)

```
$result->close();

```

$mysqli-\>close();  
exit;[/php]

The code runs w/o error, but I don’t under its output (see line 24). Two questions. 1) why the ‘NULL’ in col. 1, and 2) why are 0 rows returned?

Trying to get back to work.  
Ideas appreciated.

usit
