/    Sign up×
Community /Pin to ProfileBookmark

Publish problem?

This’s first time to publish PHP and MySQL into server i use on local machine to connect to database, “localhost” Host and “root” user name, and ofcourse it didnt want to connect to database on server. when i published the database, i published the three files in the database folder (.frm, .MYD, .MYI), what should i do to be able to connect to db, thank you for help.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsNov 10.2005 — if you have phpmyadmin on your local and remote servers, use it to export/import the database or use this script[code=php]<?php
define('SQL_SERVER', 'localhost');
define('SQL_USERNAME', 'root');
define('SQL_PASSWORD', '');
define('SQL_DATABASE', 'test');
define('SQL_PERSISTENT', 0);

define('SQL_ASSOC', 1);
define('SQL_NUM', 2);
define('SQL_BOTH', 3);

class sql_layer
{
var $id; // connection id
var $found = '';

function affected()
{
return @mysql_affected_rows($this->id);
}
function close()
{
return @mysql_close($this->id);
}
function error()
{
return @mysql_error($this->id);
}
function fetch(&$result, $result_type = SQL_BOTH)
{
return @mysql_fetch_array($result, $result_type);
}
function found()
{
$result = @mysql_query($this->found, $this->id);
$this->found = '';
return @mysql_result($result, 0);
}
function free(&$result)
{
return @mysql_free_result($result);
}
function num_cols($result)
{
return @mysql_num_fields($result);
}
function num_rows($result)
{
return @mysql_num_rows($result);
}
function query($query)
{
if(preg_match("/SQL_CALC_FOUND_ROWS/i", $query))
{
$query = preg_replace("/SQL_CALC_FOUND_ROWS/i", '', $query);
$this->found = preg_replace(array("/(?<=SELECT).+(?=FROM)/ism", "/LIMIT.+$/ism"), array(' COUNT(*) ', ''), $query);
}
return @mysql_query($query, $this->id);
}
function result($result, $row = 0, $field = NULL)
{
return @mysql_result($result, $row, $field);
}
function sql_layer()
{
$this->id = (SQL_PERSISTENT) ? @mysql_pconnect(SQL_SERVER, SQL_USERNAME, SQL_PASSWORD) : @mysql_connect(SQL_SERVER, SQL_USERNAME, SQL_PASSWORD);
return ($this->id !== false && @mysql_select_db(SQL_DATABASE, $this->id));
}
}
class sql_data extends sql_layer
{
var $data;

function comment($str)
{
$str = wordwrap($str, 54, "n");
$c = preg_split("/[rn]+/s", $str);
$r = '';

foreach($c as $s)
{
$r .= "-- $sn";
}
return $r;
}
function export($tables_to_export, $data_only = false, $file = NULL)
{
foreach($tables_to_export as $t)
{
$data = '';

if(!$data_only)
{
$res = parent::query("SHOW CREATE TABLE $t");
$data .= "-- --------------------------------------------------------nn";
$data .= $this->comment("nTable structure for table $tn") . "n";
list( , $dump) = parent::fetch($res, SQL_NUM);
$data .= $dump . ";nn";
parent::free($res);
}
$res = parent::query("SELECT * FROM $t");
$data .= $this->comment("nDumping data for table $tn") . "n";

while($row = parent::fetch($res, SQL_NUM))
{
while(list($k, $v) = each($row))
{
$row[$k] = addslashes($v);
}
$data .= "INSERT INTO $t VALUES ('" .implode("', '", $row). "');n";
}
parent::free($res);
$this->data .= $data;
}
if(!$file)
{
return $this->data;
}
else
{
$fp = @fopen($file, 'wb');
@fwrite($fp, $this->data);
@fclose($fp);
}
}
function import($file, $data_only = false)
{
if(!file_exists($file))
{
die('sql_data::import() error, file: ' .$file. ' does not exist.');
}
$fp = @fopen($file, 'rb');
$this->data = @fread($fp, @filesize($file));
@fclose($fp);
$this->uncomment();

$this->data = preg_split("/;Z/m", $this->data, NULL, PREG_SPLIT_NO_EMPTY);

for($i = 0; $i < count($this->data); $i++)
{
$this->data[$i] = trim($this->data[$i]);

if(($data_only && preg_match("/CREATE TABLE/i", $this->data[$i])) || empty($this->data[$i]))
{
unset($this->data[$i]);
}
parent::query($this->data[$i]);
}
return parent::affected();
}
function uncomment()
{
return preg_replace("/^(?:#|-+).*Z/m", '', $this->data);
}
function sql_data()
{
parent::sql_layer();

if(!$this->id)
{
die('unable to connect to database');
}
}
}
?>[/code]
export example[code=php]<?php
// ...
$sql = new sql_data;
$sql->export(array('table1', 'table2', 'etc'), 0, './db.txt');
?>[/code]
import example[code=php]<?php
// ...
$sql = new sql_data;
$sql->import('./db.txt');
?>[/code]
Copy linkTweet thisAlerts:
@CipherauthorNov 10.2005 — well i dont understand anything from the first code :rolleyes: , and i want to know why you import and export .txt files, and what does "->" this sign do, is it like "." in asp.net?! to define methods and properties?!
Copy linkTweet thisAlerts:
@CipherauthorNov 10.2005 — i tried to use the username and password i have for the website, it gave me different error this time, No DataBase Selected?!
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYNov 10.2005 — the syntax is $var->function_defined_in_class();

where $var = new class_name


are you trying that on local or on a remote server?

if it is a shared server you will usually get the credentials from your host/control panel
Copy linkTweet thisAlerts:
@CipherauthorNov 10.2005 — well i try that on remote server, and actualy i dont know if its shared or what coz its some one gave me the password and user name to log in from ftp.
×

Success!

Help @Cipher spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...