你做好程序以后,把數(shù)據(jù)庫導(dǎo)出成sql文件
在申扎等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計、網(wǎng)站制作 網(wǎng)站設(shè)計制作按需開發(fā)網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計,營銷型網(wǎng)站建設(shè),外貿(mào)網(wǎng)站制作,申扎網(wǎng)站建設(shè)費用合理。
1、連接數(shù)據(jù)庫
2、讀取這個sql文件里的sql語句,并執(zhí)行
3、生成一個數(shù)據(jù)庫連接參數(shù)的php文件
?php
$con?=?mysql_connect("localhost","peter","abc123");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
if?(mysql_query("CREATE?DATABASE?my_db",$con))
{
echo?"Database?created";
}
else
{
echo?"Error?creating?database:?"?.?mysql_error();
}
mysql_close($con);
?
?php
class?ReadSql?{
//數(shù)據(jù)庫連接
protected?$connect?=?null;
//數(shù)據(jù)庫對象
protected?$db?=?null;
//sql文件
public?$sqlFile?=?"";
//sql語句集
public?$sqlArr?=?array();
public?function?__construct($host,?$user,?$pw,?$db_name)?{
$host?=?empty($host)???C("DB_HOST")?:?$host;
$user?=?empty($user)???C("DB_USER")?:?$user;
$pw?=?empty($pw)???C("DB_PWD")?:?$pw;
$db_name?=?empty($db_name)???C("DB_NAME")?:?$db_name;
//連接數(shù)據(jù)庫
$this-connect?=?mysql_connect($host,?$user,?$pw)?or?die("Could?not?connect:?"?.?mysql_error());
$this-db?=?mysql_select_db($db_name,?$this-connect)?or?die("Yon?can?not?select?the?table:"?.?mysql_error());
}
//導(dǎo)入sql文件
public?function?Import($url)?{
$this-sqlFile?=?file_get_contents($url);
if?(!$this-sqlFile)?{
exit("打開文件錯誤");
}?else?{
$this-GetSqlArr();
if?($this-Runsql())?{
return?true;
}
}
}
//獲取sql語句數(shù)組
public?function?GetSqlArr()?{
//去除注釋
$str?=?$this-sqlFile;
$str?=?preg_replace('/--.*/i',?'',?$str);
$str?=?preg_replace('/\/\*.*\*\/(\;)?/i',?'',?$str);
//去除空格?創(chuàng)建數(shù)組
$str?=?explode(";\n",?$str);
foreach?($str?as?$v)?{
$v?=?trim($v);
if?(empty($v))?{
continue;
}?else?{
$this-sqlArr[]?=?$v;
}
}
}
//執(zhí)行sql文件
public?function?RunSql()?{
foreach?($this-sqlArr?as?$k?=?$v)?{
if?(!mysql_query($v))?{
exit("sql語句錯誤:第"?.?$k?.?"行"?.?mysql_error());
}
}
return?true;
}
}
//范例:
header("Content-type:text/html;charset=utf-8");
$sql?=?new?ReadSql("localhost",?"root",?"",?"log_db");
$rst?=?$sql-Import("./log_db.sql");
if?($rst)?{
echo?"Success!";
}
?
本文實例講述了PHP生成及獲取JSON文件的方法。分享給大家供大家參考,具體如下:
首先定義一個數(shù)組,然后遍歷數(shù)據(jù)表,把相應(yīng)的數(shù)據(jù)放到數(shù)組中,最后通過json_encode()轉(zhuǎn)化數(shù)組
json_encode()
函數(shù)的功能是將數(shù)值轉(zhuǎn)換成
JSON
數(shù)據(jù)存儲格式。
putjson.php:
?php
//
生成一個PHP數(shù)組
$data
=
array();
$data[0]
=
array('1','吳者然','onestopweb.cn');
$data[1]
=
array('2','何開','iteye.com');
//
把PHP數(shù)組轉(zhuǎn)成JSON字符串
$json_string
=
json_encode($data);
//
寫入文件
file_put_contents('test.json',
$json_string);
?
有同名的
JSON
文件則覆蓋,沒有則創(chuàng)建。
生成或覆蓋的
JSON
如下:
復(fù)制代碼
代碼如下:[["1","\u811A\u672C\u4E4B\u5BB6",""],["2","\u7F16\u7A0B\u5F00\u53D1","jb51.net"]]
然后,把
JSON
文件中的數(shù)據(jù)讀取到PHP變量中。
getjson.php:
?php
//
從文件中讀取數(shù)據(jù)到PHP變量
$json_string
=
file_get_contents('test.json');
//
把JSON字符串轉(zhuǎn)成PHP數(shù)組
$data
=
json_decode($json_string,
true);
//
顯示出來看看
var_dump($data);
echo
'brbr';
print_r($data);
echo
'brbr';
echo
'編號:'.$data[0][0].'
姓名:'.$data[0][1].'
網(wǎng)址:'.$data[0][2];
echo
'br';
echo
'編號:'.$data[1][0].'
姓名:'.$data[1][1].'
網(wǎng)址:'.$data[1][2];
?
效果圖:
PS:這里再為大家推薦幾款比較實用的json在線工具供大家參考使用:
在線JSON代碼檢驗、檢驗、美化、格式化工具:
JSON在線格式化工具:
在線XML/JSON互相轉(zhuǎn)換工具:
json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
C語言風(fēng)格/HTML/CSS/json代碼格式化美化工具:
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP中json格式數(shù)據(jù)操作技巧匯總》、《PHP針對XML文件操作技巧總結(jié)》、《PHP基本語法入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
首先說基本配置:
PHP SQLite 的使用和配置方法:
在PHP 5.1.x 以后自帶了 SQLtie 數(shù)據(jù)庫功能,只需要在配置PHP.ini中開啟即可
;extension=php_sqlite.dll
在PHP 5.2.x 以后自帶了 SQLtie PDO數(shù)據(jù)庫功能,只需要在配置PHP.ini中開啟即可
;extension=php_pdo_sqlite.dll
SQLite 數(shù)據(jù)庫管理:
1、SQLiteManager與PHPmyadmin不同,需要添加管理的數(shù)據(jù)庫
2、Windows下使用添加路徑需要將 X: \**\** 改為 X:/**/**
3、 創(chuàng)建數(shù)據(jù)庫的時候需要指定SQLite 數(shù)據(jù)庫文件存放的路徑
再說操作:
?php
$db_path = 'sqlite3_db_php';
$db = new SQLite3($db_path); //這就是創(chuàng)建數(shù)據(jù)庫,也是連接數(shù)據(jù)庫
if (!!$db) {
//下面創(chuàng)建一個表格
$db-exec('CREATE TABLE user (id integer primary key, name varchar(32), psw varchar(32))');
使用ming庫,?php
$img = new SWFBitmap( file_get_contents( 'megan.jpg' ) );
$s = new SWFShape();
$imgf = $s-addFill( $img );
$s-setRightFill( $imgf );
$s-movePenTo( 0, 0 );
$s-drawLineTo( $img-getWidth(), 0 );
$s-drawLineTo( $img-getWidth(), $img-getHeight() );
$s-drawLineTo( 0, $img-getHeight() );
$s-drawLineTo( 0, 0 );
$m = new SWFMovie();
$m-setDimension( $img-getWidth() * 2, $img-getHeight() * 2 );
$is = $m-add( $s );
$is-moveTo( $img-getWidth() / 2, $img-getHeight() / 2 );
for( $i = 0; $i 10; $i++ )
{
$is-skewx( 0.02 );
$is-skewy( -0.03 );
$m-nextframe();
}
$m-save( 'image.swf' );
?