Asked  7 Months ago    Answers:  5   Viewed   41 times

I have a problem with phpmyadmin on ubuntu 12.04. I have already installed apache2, php5, mysql and phpmyadmin.

The phpinfo(); script, don't show nothing about mysqli or mysql extension.

When I try start phpmyadmin this error appear:

----
**phpMyAdmin - Error**
-------
**The mysqli extension is missing. Please check your PHP configuration.**
----

In the php.ini file, I uncommented extension=mysql.so line, but doesn't work...

Anyone have another posible solution?

 Answers

15

Just restart the apache2 and mysql:

  • apache2: sudo /etc/init.d/apache2 restart

  • mysql: sudo /etc/init.d/mysql restart

then refresh your browser, enjoy phpmyadmin :)

Wednesday, March 31, 2021
 
DiglettPotato
answered 7 Months ago
79

The CREATE DATABASE statement is used to create a database in MySQL.

  • Syntax:
CREATE DATABASE database_name 

To get PHP to execute the SQL instructions, first you must create a mysqli object with the connection to the server, then use the query() method of the MySQLi class.

  • Syntax:
mysqliObj->query($sql_query)
  • mysqliObj - is the mysqli object created with new mysqli()
  • $sql_query - is a string with SQL instructions. This method sends a query or command to a MySQL connection, will return a result object, or TRUE on success. FALSE on failure.

The following example creates a database called "tests":

<?php
// connect to the MySQL server
$conn = new mysqli('localhost', 'root', 'pass');

// check connection
if (mysqli_connect_errno()) {
  exit('Connect failed: '. mysqli_connect_error());
}

// sql query with CREATE DATABASE
$sql = "CREATE DATABASE `tests` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";

// Performs the $sql query on the server to create the database
if ($conn->query($sql) === TRUE) {
  echo 'Database "tests" successfully created';
}
else {
 echo 'Error: '. $conn->error;
}

$conn->close();
?>

Check this link http://coursesweb.net/php-mysql/php-mysql-using-mysqli

Wednesday, March 31, 2021
 
VieStar
answered 7 Months ago
49

To be sure you see all PHP errors, add this code on top of your script:

error_reporting(E_ALL);
ini_set('display_errors', 1);

You must correct your calls to mysqli_real_escape_string. According to the documentation, there must be two parameters, and the first parameter must be a MySQL link. In your case that link would be $mysqli.

Also, replace:

if($row==1){

with:

if($result->num_row==1){

You are misunderstanding what $result->num_rows is: it contains the TOTAL number of rows returned by the query whose result is stored in $result. So, it is useless to check the value of $result->num_rows inside the loop where you retrieve all records returned by the query.

I removed the constant MYSQLI_USE_RESULT from your query() because the documentation for mysqli_query says:
If you use MYSQLI_USE_RESULT all subsequent calls will return error Commands out of sync unless you call mysqli_free_result().

New code:

<?php
    $mysqli = new mysqli('localhost', 'root', 'password', 'aiesec');

    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %sn", mysqli_connect_error());
        exit();
    }

    // cleanup POST variables
    $myusername = mysqli_real_escape_string($mysqli, stripslashes(trim($_POST['myusername'])));
    $mypassword = mysqli_real_escape_string($mysqli, stripslashes(trim($_POST['mypassword'])));

    // If result matched $myusername and $mypassword, table row must be 1 row
    $sql = "SELECT * FROM members WHERE username='$myusername' and password='$mypassword'"; 
    $result = mysqli->query($sql);
     if($mysqli->errno<>0)
        die("Errormessage: %sn", $mysqli->error);
    echo $result->num_rows;
    if($result->num_rows==1){
        echo "correct username and pass";
        // Register $myusername, $mypassword and redirect to file "login_success.php"
       // session_register("myusername");
        //session_register("mypassword");
        //header("location:login_success.php");
    }
    else {
        echo "Wrong Username or Password";
    }
    mysqli_close();     
?>
Friday, May 28, 2021
 
twk
answered 5 Months ago
twk
66

Maybe this would be

  $mysql_host="localhost";// for local server

Or

 $mysql_host="$ip";// if database is in remote and IP is stored in $ip
Saturday, May 29, 2021
 
MGP
answered 5 Months ago
MGP
56

I can give you my build recipe from a fresh 12.04 installation. Fresh being simply running through the configuration and only selecting the "SSH server" option at the end for convenience.

MongoDB installation is optional, so if you want this on a different server then skip. But the general instructions come from:

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

All commands split up and not automated so you can see the steps:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get install software-properties-common
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
sudo apt-get install mongodb-10gen
sudo apt-get install build-essential
sudo apt-get install php5-dev
sudo apt-get install libcurl4-openssl-dev
sudo pecl install mongo

Lots of compiler output. Ending with success and asking to mofidy php.ini

Edit the CLI settings. And do the same for the apache config as well

sudo vi /etc/php5/cli/php.ini
sudo vi /etc/php5/apache2/php.ini

Personal preference, after the comments on 'Dynamic Extensions'

extension=mongo.so

Test that usage and connection does not throw an error. Create test.php:

<?php

    $m = new MongoClient('mongodb://localhost/',
        array('connectTimeoutMS'=> 500, 'socketTimeoutMS' => 500 ));

?>

And run from command line:

php test.php

No errors. Then you are all set up.

$ php -v
PHP 5.5.3-1ubuntu2.1 (cli) (built: Dec 12 2013 04:24:35)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
Friday, August 6, 2021
 
BaajiRao
answered 3 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 :