Help with turning MySQL into MySQLi?

Status
Not open for further replies.

designzx

New Member
Messages
4
Reaction score
0
Points
1
How do I turn:

mysql_connect

Into mysqli? When I did:

mysqli_connect

I get errors.
 

designzx

New Member
Messages
4
Reaction score
0
Points
1
Starts telling me other lines are messed up, or 'expects Boolean to be 2 resource' or something like that.
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
Here's what I did (you can use different more secure functions if you need so, this is just the basics):
PHP:
$conn = mysqli_connect('localhost','username','password','database');
if(!$conn) {
    exit('Connection failed, and I\'m not gonna tell the public why because the error_log should be the only thing that should carry such information! And the error_log is also not made accessible via Apache!');
}

if(isset($_GET['lime'])) {
    $lime = $_GET['lime'];
    $lime = mysqli_real_escape_string($conn, $lime);
}
else {
    $lime = '';
}
if(isset($_GET['fruit'])) {
    $fruit = $_GET['fruit'];
    $fruit = mysqli_real_escape_string($conn, $fruit);
}
else {
    $fruit = '';
}

$query = mysqli_query($conn, "SELECT something FROM table WHERE something='$lime' AND apple='$fruit'");
$result = mysqli_fetch_assoc($query);
echo $result;

That is just an example to show how it would be laid out. You can always visit the PHP documentation to see some additional stuff. And yes, I didn't sort out XSS/CSS/HTML injections with this because that's not what I'm trying to show here.
 
Status
Not open for further replies.
Top