Jump to content

Configurare fisier config.php pentru baza de date?


Micul`wji

Recommended Posts

Buna tuturor, nu reusesc sa conectez un joc de browser la o baza de date completez cum trebuie fisierul config.php (cel putin asa cred eu) si primesc eroare peste eroare o sa las aici jos fisierul config si va rog eu sa-mi spuneti si mie unde trebuie configurat.

momentan am configurat urmatoarele... si tot primmesc erori

<?php
//Database Connection
$host   = "localhost";
$dbuser = "root";
$dbpass = "parola";
$db     = "xrace_pro";
$db_conn = mysql_connect("$host", "$dbuser", "$dbpass") or die("Unable to connect to the database");
mysql_select_db("$db", $db_conn) or die("Unable to select the database");
mysql_query("SET CHARACTER SET utf8");
?>

 

<?php
//Database Connection
$host   = "localhost";
$dbuser = "root";
$dbpass = "parola";
$db     = "xrace_pro";
$db_conn = mysql_connect("$host", "$dbuser", "$dbpass") or die("Unable to connect to the database");
mysql_select_db("$db", $db_conn) or die("Unable to select the database");
mysql_query("SET CHARACTER SET utf8");

//Set Online
@session_start();
@$user = $_SESSION['username'];
$selectuser = mysql_query("SELECT * FROM users WHERE username='$user'");
if (mysql_num_rows($selectuser) > 0) {
    $urow    = mysql_fetch_array($selectuser);
    $timenow = time();
    $update  = mysql_query("UPDATE users SET timeonline='$timenow' WHERE username='$user'");
} else {
    session_unset();
}

//Level Up
if (mysql_num_rows($selectuser) > 0) {
    $wins         = $urow['wins'];
    $losses       = $urow['losses'];
    $userraces    = $wins + $losses;
    $userlevel    = $urow['level'];
    $levels       = mysql_query("SELECT * FROM levels WHERE level='$userlevel'");
    $lrow         = mysql_fetch_array($levels);
    $minraces     = $lrow['minraces'];
    $biggerlevels = mysql_query("SELECT * FROM levels WHERE level='$userlevel'+1");
    $lbrow        = mysql_fetch_array($biggerlevels);
    $blevel       = $lbrow['level'];
    $bminraces    = $lbrow['minraces'];
    
    if ($userraces > $minraces && $userraces > $bminraces OR $userraces == $bminraces) {
        $update = mysql_query("UPDATE users SET level='$blevel' WHERE username='$user'");
    }
    if ($userraces < $minraces) {
        $update = mysql_query("UPDATE users SET level=level-1 WHERE username='$user'");
    }
}

//Fuel Refill (by default every 10 minutes)

//$run  = mysql_query("SELECT * FROM `settings`");
//$site = mysql_fetch_assoc($run);
//$refilltime = $site['refilltime'];
//$refilltimetype = $site['fullrefilltimetype'];
//$fullrefilltime = $site['fullrefilltime'];
//$fullrefilltimetype = $site['refilltimetype'];
//$run2  = mysql_query("SELECT * FROM `cron-tasks` WHERE type='fuelrefill'");
//$site2 = mysql_fetch_assoc($run2);
//$lastrun = $site2['lastrun'];
//$timenow = time();
//if ($refilltimetype == "hours") {
//$plustime = $refilltime*3600;
//} else {
//if ($refilltimetype == "minutes") {
//$plustime = $refilltime*60;
//} else {
//if ($refilltimetype == "seconds") {
//$plustime = $refilltime;
//}
//}
//}
//$run3  = mysql_query("SELECT * FROM `cron-tasks` WHERE type='fullfuelrefill'");
//$site3 = mysql_fetch_assoc($run3);
//$lastrun2 = $site3['lastrun'];
//if ($fullrefilltimetype == "hours") {
//$plustime2 = $fullrefilltime*3600;
//} else {
//if ($fullrefilltimetype == "minutes") {
//$plustime2 = $fullrefilltime*60;
//} else {
//if ($fullrefilltimetype == "seconds") {
//$plustime2 = $fullrefilltime;
//}
//}
//}

//if(mysql_num_rows($selectuser)>0) {
//if ($urow['fuel'] < $urow['fuelcapacity']) {
//$timenow = time();
//if($timenow >= $lastrun + $plustime) {
//$timenow = time();
//$sqlusers = mysql_query("SELECT * FROM users WHERE banned='No'");
//while ($rowuser = mysql_fetch_assoc($sqlusers)) {
//$userrefillfuel = mysql_query("UPDATE users SET fuel=fuel+1 WHERE username='$rowuser[username]'");
//}
//$updaterun = mysql_query("UPDATE `cron-tasks` SET lastrun='$timenow' WHERE type='fuelrefill'");
//}
//}

//$timenow = time();
//if($timenow >= $lastrun2 + $plustime2) {
//$timenow = time();
//$sqlusers = mysql_query("SELECT * FROM users WHERE banned='No'");
//while ($rowuser = mysql_fetch_assoc($sqlusers)) {
//$userrefillfuel = mysql_query("UPDATE users SET fuel='$rowuser[fuelcapacity]' WHERE username='$rowuser[username]'");
//}
//$updaterun2 = mysql_query("UPDATE `cron-tasks` SET lastrun='$timenow' WHERE type='fullfuelrefill'");
//}

//}
?>

si asta ar fi una dintre erori:

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u250338952/public_html/config.php on line 7

puteti spune ce mai trebuie completat?
Multumesc!

- Mă tem că intr-o zi tehnologia va întrece umanitatea iar lumea va avea o generație de idioți !

Albert Einstein

:(

Link to comment
Share on other sites

  • Moderators

Functia mysql_connect() este deprecated de la PHP 5.5.. Cum bine iti spune mesaj-ul, foloseste mysqli sau PDO:

http://php.net/manual/en/book.mysqli.php

http://php.net/manual/es/book.pdo.php

PHP Developer - Not available for freelancing right now

Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament

Link to comment
Share on other sites

deci mai exact fac urmatorul lucru?

 

$db_conn = mysql_connect("$host", "$dbuser", "$dbpass") or die("Unable to connect to the database");

asa ar trebui sa arate?

$db_conn = mysqli_connect("$host", "$dbuser", "$dbpass") or die("Unable to connect to the database");

 

- Mă tem că intr-o zi tehnologia va întrece umanitatea iar lumea va avea o generație de idioți !

Albert Einstein

:(

Link to comment
Share on other sites

<?php
//Database Connection
$host   = "localhost";
$dbuser = "root";
$dbpass = "";
$db     = "test";
$db_conn = new mysqli($host, $dbuser, $dbpass, $db);
if ($db_conn->connect_errno) {
    echo "Failed to connect to MySQL: (" . $db_conn->connect_errno . ") " . $db_conn->connect_error;
}
?>

Asta este doar partea in care te conectezi, nu stiu ce erori iti mai apar..

Link to comment
Share on other sites

deci intr-un final script trebuie sa arate asa?

cu mysqli

<?php
//Database Connection
$host   = "host";
$dbuser = "nume";
$dbpass = "parola baza de date";
$db     = "nume";
$db_conn = new mysqli(host, nume, parola, nume);
if ($db_conn->connect_errno) {
    echo "Failed to connect to MySQL: (" . $db_conn->connect_errno . ") " . $db_conn->connect_error;
}
?>

dar am toata pagina plina cu erori....

 

Spoiler
  • Warning: mysql_query(): Access denied for user 'u250338952'@'10.2.1.47' (using password: NO) in /home/u250338952/public_html/core.php on line 158

    Warning: mysql_query(): A link to the server could not be established in /home/u250338952/public_html/core.php on line 158

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/u250338952/public_html/core.php on line 159

    Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u250338952/public_html/core.php on line 228

    Warning: mysql_query(): Access denied for user 'u250338952'@'10.2.1.47' (using password: NO) in /home/u250338952/public_html/core.php on line 228

    Warning: mysql_query(): A link to the server could not be established in /home/u250338952/public_html/core.php on line 228

    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/u250338952/public_html/core.php on line 229

si normal arata asa:

<?php
//Database Connection
$host   = "localhost";
$dbuser = "root";
$dbpass = "parola";
$db     = "xrace_pro";
$db_conn = mysql_connect("$host", "$dbuser", "$dbpass") or die("Unable to connect to the database");
mysql_select_db("$db", $db_conn) or die("Unable to select the database");
mysql_query("SET CHARACTER SET utf8");

si am urm eroare...

Spoiler

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u250338952/public_html/config.php on line 7

chiar nu ma poate ajuta nimeni?

- Mă tem că intr-o zi tehnologia va întrece umanitatea iar lumea va avea o generație de idioți !

Albert Einstein

:(

Link to comment
Share on other sites

Ai incercat si pe alt host? Nu de alta dar am vaga impresie ca folosesti 000webhost si stiu ca sunt niste restrictii. Asta in cazul in care completezi bine datele de conectare la baza de date.

Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

Link to comment
Share on other sites

nu folosesc 000webhost am host platit :D si da @gaby am configurat corect baza de date... doar ca primesc urmatoarea eroare...

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u250338952/public_html/config.php on line 7

iar  linia 7 este urmatoarea:

$db_conn = mysql_connect("$host", "$dbuser", "$dbpass") or die("Unable to connect to the database");

si este configurata bine...

- Mă tem că intr-o zi tehnologia va întrece umanitatea iar lumea va avea o generație de idioți !

Albert Einstein

:(

Link to comment
Share on other sites

Ti-a spus si @gadeas ca functia mysql_connect() este deprecated/anulata incepand cu versiunea PHP 5.5 si este indicat sa renunti la ea. Ca alternativa la mysql_connect() poti invata si folosi MySQLi sau PDO. Incearca pe localhost si o sa vezi ca iti merge, asa pe host ca sa stai tu si sa rezolvi toate erorile te asigur ca iti va lua ceva timp

Link to comment
Share on other sites

@Stefan eu am doar o singura eroare de rezolvat.... mai exact cea cu functia mysql... daca cineva mi-ar schimba fisierul config.php cu unu updatat cu mysqli ar fi perfect nu as mai avea nici o eroare... Eu unul nu reusesc de fel

 

toate acele erori multe au fost din cauza ca am distrus fisierul config.php ca am incercat sa modific dar nu am reusit...

- Mă tem că intr-o zi tehnologia va întrece umanitatea iar lumea va avea o generație de idioți !

Albert Einstein

:(

Link to comment
Share on other sites

  • Moderators

Degeaba schimbi doar aia de la config.php, pentru ca script-ul ce incerci sa folosesti sigur mai foloseste query-uri cu baza de date si in alte locuri, acolo la fel trebuie sa schimbi in noul format de a lucra cu mysqli sau PDO.

PHP Developer - Not available for freelancing right now

Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament

Link to comment
Share on other sites

14 hours ago, gadeas said:

Degeaba schimbi doar aia de la config.php, pentru ca script-ul ce incerci sa folosesti sigur mai foloseste query-uri cu baza de date si in alte locuri, acolo la fel trebuie sa schimbi in noul format de a lucra cu mysqli sau PDO.

da aici ai mare dreptate... :D

 

intr-un final ce pot face in afara de update la script pentru pdo sau mysqli ?

- Mă tem că intr-o zi tehnologia va întrece umanitatea iar lumea va avea o generație de idioți !

Albert Einstein

:(

Link to comment
Share on other sites

5 minutes ago, gadeas said:

Sa scazi versiunea de PHP folosita pe server la 5.4.

@gadeas mersi mult de tot... nustiu cum de am fost asa de neatent incat sa nu imi dau seama de aceasta rezolvarea usoara :D 

 

Topic rezolvat !

 

- Mă tem că intr-o zi tehnologia va întrece umanitatea iar lumea va avea o generație de idioți !

Albert Einstein

:(

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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.