Hi there, 🙂
I have a question. Maybe it's a simple one, but not for me.
I have setup apache/php and MYsql on my raq4.
I changed my mysql root password and host password.
I have a php script for my counter-strike server, that people can type a message in the page and it will be send with an other app.
but what a user sends to the server, will be placed in a database
and shown in my php.
but when i use it it does nothing. I have made a database 'talk' and a table 'webtalk'
Soory but it's a very long script.
A talk.php with a include(init_db.php).
init_db with a include(mysql.php). In the last it setup a connection to mysql. But whatever i use. It will not connect. I think. whats wrong the connect script or a error in my sql config. this is the script:
<?php
error_reporting(0);
class DB_Sql {
// set these !!!
var $server = "serverip/localhost";
var $user = "databaseuser";
var $password = "userpassword";
var $database = "tableset";
// leave these...
var $link_id = 0;
var $query_id = 0;
var $record = array();
var $errdesc = "";
var $errno = 0;
var $reporterror = 1;
function connect() {
global $usepconnect;
// connect to db server
if ( 0 == $this->link_id ) {
if ($this->password=="") {
if ($usepconnect==1) {
$this->link_id=mysql_pconnect($this->server,$this->user);
} else {
$this->link_id=mysql_connect($this->server,$this->user);
}
} else {
if ($usepconnect==1) {
$this->link_id=mysql_pconnect($this->server,$this->user,$this->password);
} else {
$this->link_id=mysql_connect($this->server,$this->user,$this->password);
}
}
if (!$this->link_id) {
$this->halt("Link-ID == false, connect failed");
}
if ($this->database!="") {
if(!mysql_select_db($this->database, $this->link_id)) {
$this->halt("cannot use database ".$this->database);
}
}
}
}
function geterrdesc() {
$this->error=mysql_error();
return $this->error;
}
function geterrno() {
$this->errno=mysql_errno();
return $this->errno;
}
function select_db($database="") {
// select database
if ($database!="") {
$this->database=$database;
}
if(!mysql_select_db($this->database, $this->link_id)) {
$this->halt("cannot use database ".$this->database);
}
}
function query($query_string) {
global $query_count,$showqueries,$explain,$querytime;
// do query
$this->query_id = mysql_query($query_string,$this->link_id);
if (!$this->query_id) {
$this->halt("Invalid SQL: ".$query_string);
}
$query_count++;
if ($showqueries) {
$pageendtime=microtime();
$starttime=explode(" ",$pagestarttime);
$endtime=explode(" ",$pageendtime);
$aftertime=$endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];
$querytime+=$aftertime-$beforetime;
echo "Time after: $aftertime\n";
if ($explain and substr(trim(strtoupper($query_string)),0,6)=="SELECT") {
$explain_id = mysql_query("EXPLAIN $query_string",$this->link_id);
echo "</pre>\n";
echo "
<table width=100% border=1 cellpadding=2 cellspacing=1>
<tr>
<td><b>table</b></td>
<td><b>type</b></td>
<td><b>possible_keys</b></td>
<td><b>key</b></td>
<td><b>key_len</b></td>
<td><b>ref</b></td>
<td><b>rows</b></td>
<td><b>Extra</b></td>
</tr>\n";
while($array=mysql_fetch_array($explain_id)) {
echo "
<tr>
<td>$array[table] </td>
<td>$array[type] </td>
<td>$array[possible_keys] </td>
<td>$array[key] </td>
<td>$array[key_len] </td>
<td>$array[ref] </td>
<td>$array[rows] </td>
<td>$array[Extra] </td>
</tr>\n";
}
echo "</table>\n<BR><hr>\n";
echo "\n<pre>";
} else {
echo "\n<hr>\n\n";
}
}
return $this->query_id;
}
function fetch_array($query_id=-1,$query_string="") {
// retrieve row
if ($query_id!=-1) {
$this->query_id=$query_id;
}
if ( isset($this->query_id) ) {
$this->record = mysql_fetch_array($this->query_id);
} else {
if ( !empty($query_string) ) {
$this->halt("Invalid query id (".$this->query_id.") on this query: $query_string");
} else {
$this->halt("Invalid query id ".$this->query_id." specified");
}
}
return $this->record;
}
function free_result($query_id=-1) {
// retrieve row
if ($query_id!=-1) {
$this->query_id=$query_id;
}
return @mysql_free_result($this->query_id);
}
function query_first($query_string) {
// does a query and returns first row
$query_id = $this->query($query_string);
$returnarray=$this->fetch_array($query_id, $query_string);
$this->free_result($query_id);
return $returnarray;
}
function data_seek($pos,$query_id=-1) {
// goes to row $pos
if ($query_id!=-1) {
$this->query_id=$query_id;
}
return mysql_data_seek($this->query_id, $pos);
}
function num_rows($query_id=-1) {
// returns number of rows in query
if ($query_id!=-1) {
$this->query_id=$query_id;
}
return mysql_num_rows($this->query_id);
}
function num_fields($query_id=-1) {
// returns number of fields in query
if ($query_id!=-1) {
$this->query_id=$query_id;
}
return mysql_num_fields($this->query_id);
}
function insert_id() {
// returns last auto_increment field number assigned
return mysql_insert_id($this->link_id);
}
function close() {
// closes connection to the database
return mysql_close();
}
function halt($msg) {
$this->errdesc=mysql_error();
$this->errno=mysql_errno();
// prints warning message when there is an error
if ($this->reporterror==1) {
$message="Database error in $this->appname $GLOBALS[templateversion]:\n\n$msg\n";
$message.="mysql error: $this->errdesc\n\n";
$message.="mysql error number: $this->errno\n\n";
$message.="Date: ".date("l dS of F Y h:i:s A")."\n";
$message.="Script: $GLOBALS[bburl]" . (($scriptpath) ? $scriptpath : getenv("REQUEST_URI")) . "\n";
$message.="Referer: ".getenv("HTTP_REFERER")."\n";
echo "<html><head><title>$GLOBALS[bbtitle] Database Error</title><style>P,BODY{FONT-FAMILY:tahoma,arial,sans-serif;FONT-SIZE:11px;}</style><body>\n\n<!-- $message -->\n\n";
echo "</table></td></tr></table></form>\n<blockquote><p> </p><p><b>There seems to have been a slight problem with the $GLOBALS[bbtitle] database.</b><br>\n";
echo "Please try again by pressing the <a href=\"javascript:window.location=window.location;\">refresh</a> button in your browser.</p>";
echo "<p>We apologise for any inconvenience.</p>";
echo "</blockquote></body></head></html>";
exit;
}
}
}
====That's it.
Whatever i use for host => localhost/ip/host
and for user=> root/host/'a self made user'
pass is pass 🙂
and database 'talk'.
I won't work 🙁
I hope someone can help me 😛
Thanx in advance 🙂
The Glimmerman