Jump to content

function prepare() on null mixing Object and Procedural


Adamhumbug

Recommended Posts

Hi All,

I have the following code which works fine:

$mysqli = new mysqli("server", "user", "pass", "database");
if($mysqli->connect_error) {
exit('Could not connect');
}



$sql = "SELECT customer_contactname, customer_companyname, customer_phonenumber, customer_emailaddress, customer_address1, customer_address2, customer_city, customer_postcode
FROM ssm_customer WHERE customer_id = ?";

$stmt = $mysqli->prepare($sql);
$stmt->bind_param("s", $_GET['q']);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($ccontname, $ccompname, $cphoneno, $cemail, $cad1, $cad2, $ccity, $cpost);
$stmt->fetch();
$stmt->close();

however, when i use my dbconn.php as an include rather than the top section of this code, i get the following error: function prepare() on null

The error references the following

$stmt = $mysqli->prepare($sql);

In my database connection file, i am using the following:

$conn = mysqli_connect($db_servername, $db_username, $db_password, $db_name);

This seems to be the issue and i believe i am mixing procedural and object based but not sure why there should be a difference here?

when i used my database connection file, i do change $mysqli->prepare to $conn->prepare

Kind Regards

Edited by Adamhumbug
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.