News:

MFG's Character of the Month: October 2026 Nominations

Main Menu

SQL

Started by Jh0nnY2k, June 09, 2016, 10:45:40 PM

Previous topic - Next topic

Jh0nnY2k

So i'm following some video courses. Not online but.... i'm trying to follow them to the letter. And something doesn't add up.

I got this :

Quote
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
       require_once 'includes/conexiune.php';
       mysql_query("
           CREATE TABLE `produse` (
           `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `nume` VARCHAR(30) NOT NULL
           )");

        ?>
    </body>
</html>


and the second page : includes/conexiune.php

Quote
<?php

mysql_connect("localhost", "ionut222", "123456") or die("Conexiune esuata");
mysql_select_db("php1c5") or die("Selectare esuata a bazei de date");

?>

If i run the page i get this error :

Quote
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp\htdocs\Proiect08\includes\conexiune.php:3 Stack trace: #0 C:\xampp\htdocs\Proiect08\index.php(14): require_once() #1 {main} thrown in C:\xampp\htdocs\Proiect08\includes\conexiune.php on line 3

and the table doesn't get created ofc....

HELP?

The dude i'm watching the video from just types these thigs and he gets everything working. As for me not working.


Алексей

The error says that it cannot find the "mysql_connect" function. Make sure that you have MySQL running and the module active in XAMPP. If I recall correctly, XAMPP comes with a PhpMyAdmin integration. You can check your database data with it. Make sure you can connect to that as well.

-[Все слова это только слова.]-

Jh0nnY2k

So:)) this is wierd. If i try to access localhost/phpmyadmin/ it works just fine. i can create databases users etc etc.

The script i did earlier doesn't work:) i tried running the script the teacher did and left on the course. It gives another error that it cannot find the localhost. Ok everything is logical.

In this time both the apache and the mysql server are running(modules installed) and i did a new test with firewall off .

So everything points out that the mysql server doesn't work properly:) ok now i say ok let's do another test and i look for another course online.


and i do this :

Quote
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "php1c5";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// sql to create table
$sql = "CREATE TABLE produse (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
nume VARCHAR(30) NOT NULL,
prenume VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";

if ($conn->query($sql) === TRUE) {
    echo "Table MyGuests created successfully";
} else {
    echo "Error creating table: " . $conn->error;
}

$conn->close();
?>
    </body>
</html>

And guess what. Now it works.(it works with the second script but not with the first) WTF? What is possibly going wrong? Mysql server problem?

Алексей

In the second script you're using mysqli, which is a different set of methods from mysql in php. It's possible that your XAMPP installation is configured to use mysqli instead of mysql. Mysqli is the superior of the two (in my opinion) anyways, so there's nothing wrong with that.

-[Все слова это только слова.]-

Jh0nnY2k

Ok thanks for the help:) I'm going with the second version then. I'm gonna learn that.

If you ever come trough Bucharest give me a ping and i'll buy you a drink :)

Алексей

Haha, no worries. :)

-[Все слова это только слова.]-

Jh0nnY2k

#6
So, yeah. Those command ( the first set) are from php5 . And at home i have installed php7. Php7 has removed them and passed on to mysqli.

Last update:  yeah replaced server (php5) and it worked like a charm.

Jesuszilla

For the record, PHP5 is the main standard. I'd avoid PHP7, especially if you're learning PHP, unless you have good reason.

Алексей

Quote from: Jesuszilla on June 12, 2016, 04:00:26 AM
For the record, PHP5 is the main standard. I'd avoid PHP7, especially if you're learning PHP, unless you have good reason.

Agreed.

-[Все слова это только слова.]-

Jh0nnY2k

#9
Thank you:) I'll do that i'll stick to php5