Asked  7 Months ago    Answers:  5   Viewed   35 times

I am doing a tutorial and am getting this error:

Fatal error: Class 'MySQLi' not found (LONG URL) on line 8

The code on line 8 is:

$mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name);

I saw online someone said to see if it was turned on in my phpinfo(), but there wasn't anything listed in there under for "mysqli".

Also, I am running PHP version 5.2.5

 Answers

78

Sounds like you just need to install MySQLi.

If you think you've done that and still have a problem, please post your operating system and anything else that might help diagnose it further.

Wednesday, March 31, 2021
 
rblarsen
answered 7 Months ago
45

Replace this include './connection.php'; to include 'connection.php';
Replace you class name connection to Connection

Saturday, May 29, 2021
 
CAMason
answered 5 Months ago
35

Code should be

<?php

    #FileName = "Connection_php_mysql.htm"
    #Type = "MYSQL"
    #HTTP = "true"

    $hostname_Main_DB = "localhost";
    $database_Main_DB = "mydb";
    $username_Main_DB = "root";
    $password_Main_DB = "";

    $con = mysqli_connect($hostname_Main_DB,$username_Main_DB,$password_Main_DB, $database_Main_DB) or die ( "Failed to connect to MySQL: " . mysqli_connect_errno());

    $db=mysqli_select_db($database_Main_DB,$con) or die( "Failed to connect to MySQL: ".mysqli_connect_errno());
?>

You should remove "new". For more information read this

Edit :-

Also you have added . in between two variable that should be ,

$username_Main_DB. $password_Main_DB replace this with $username_Main_DB,$password_Main_DB

Saturday, May 29, 2021
 
ramdemon
answered 5 Months ago
39

yo need create the user "pma" in mysql or change this lines(user and password for mysql):

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = '';

Linux: /etc/phpmyadmin/config.inc.php

Tuesday, July 13, 2021
 
ShadowZzz
answered 4 Months ago
36

This is how your code should look (with added SQL Injection protection):

<?php
include "dbinfo.php"; //contains mysqli_connect information (the $mysqli variable)
//inputs
$name = mysqli_real_escape_string($_GET['name']);
$text = mysqli_real_escape_string($_GET['text']);

$sqlqr = "INSERT INTO `ncool`.`coolbits_table` (`name`, `text`, `date`) VALUES ('" . $name . "', '" . $text . "', CURRENT_TIMESTAMP);";

mysqli_query($mysqli,$sqlqr); //function where the magic happens.
?>

Take a look at what I've done. Firstly I've escaped the user input you're retrieving into the $name and $text variables (this is pretty much a must for security reasons) and as others have suggested you should preferably be using prepared statements.

The problem is that you weren't surrounding string values with single quotes ('), which is a requirement of the SQL syntax.

I hope this helps to answer your question.

Thursday, September 2, 2021
 
Pachvarsh
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share