Jump to content

Changing code to MySqli


AAC-Bob

Recommended Posts

I am attempting to change some php code to mysqli.

I'm not a skilled programmer and am running into some query problems.

 

Here is the Existing code;

Here is the Existing code;

<?php

$link = mysql_connect($config['DB_Host'], $config['DB_User'], $config['DB_Passwd']) or die('Cannot connect to the database');

mysql_select_db($config['DB_Name'],$link) or die('Cannot select the database');

 

parse_str(str_replace(':', '&', $_COOKIE['UserSettings']),$userInfo);

$MemberID = $userInfo["MemberID"];

 

$query = "SELECT PersonID FROM `membershipperson` where MembershipID = ".$MemberID;

$result = mysql_query($query) or die ("Errant Query: ".$query);

$record = mysql_fetch_array($result);

$personID = $record["PersonID"];

 

# additional code below

?>

New Code

<?php

include ("mySqli_conn.php");

$result = $link->query($sql)or die('Cannot select the database');

 

parse_str(str_replace(':', '&', $_COOKIE['UserSettings']),$userInfo);

$MemberID = $userInfo["MemberID"];

 

$sql = "SELECT PersonID FROM `membershipperson` where MembershipID = ".$MemberID;

 

$result = $link->query($sql)or die ("Errant Query: ".$query);

$result->fetch_array($result);

 

$personID = $record["PersonID"];

?>

 

Error

Warning: mysqli::query() [mysqli.query]: Empty query in /~/position.php on line 6

Cannot select the database

 

Thanks,

Bob C

Link to comment
Share on other sites

It because of this here

<?php
include ("mySqli_conn.php");
$result = $link->query($sql)or die('Cannot select the database');

What query are you trying to run here. Basically $sql is either empty or not defined. So you are getting the Empty query error message.

 

Is this for selecting the database to use? If its you tell mysqli what database to use when you connect.

$link = new mysqli('hostname', 'username', 'password', 'database name'); // object
// OR
$link = mysqli_connect('hostname', 'username', 'password', 'database name'); // procedural 
Edited by Ch0cu3r
Link to comment
Share on other sites

 

 

It because of this here

<?phpinclude ("mySqli_conn.php");$result = $link->query($sql)or die('Cannot select the database');
What query are you trying to run here. Basically $sql is either empty or not defined. So you are getting the Empty query error message.

 

Is this for selecting the database to use? If its you tell mysqli what database to use when you connect.

$link = new mysqli('hostname', 'username', 'password', 'database name'); // object// OR$link = mysqli_connect('hostname', 'username', 'password', 'database name'); // procedural
 

 

 

I use the include ("mySqli_conn.php"); for all my php database mysqli connections.

I have 4 other pages using this common file that work just fine.

 

If this is the problem then I am confused.

 

Bob

Link to comment
Share on other sites

&nbsp;

The include is not the issue. Its this

$result = $link-&gt;query($sql)or die('Cannot select the database');
That is what is causing the error. Delete it.
&nbsp;

 

OK I removed it and error gone, TNX,

Edited by AAC-Bob
Link to comment
Share on other sites

Hi Ch0cu3r,

 

I went to the link and resolved the problem. Thank you.

 

OK now one more I can't seam to solve;

 

original; while($row2 = mysql_fetch_array($results2))

 

tried; while($row2 = $result2->fetch_array())

 

 

error: Warning: mysql_fetch_array() expects parameter 1 to be resource, null given

 

Bob

Edited by AAC-Bob
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.