<?<span>php </span><span>$con</span> = <span>mysql_connect</span>("localhost:3306","root",""<span>); </span><span>if</span> (!<span>$con</span><span>) { </span><span>die</span>('Could not connect: ' . <span>mysql_error</span><span>()); } </span><span>mysql_select_db</span>("test", <span>$con</span><span>); </span><span>$result</span> = <span>mysql_query</span>("SELECT * FROM user"<span>); </span><span>echo</span> "<span><table border='1'> <tr> <th>Username</th> <th>Password</th> </tr>"<span>; </span><span>while</span>(<span>$row</span> = <span>mysql_fetch_array</span>(<span>$result</span><span>)) { </span><span>echo</span> "<tr>"<span>; </span><span>echo</span> "<td>" . <span>$row</span>['username'] . "</td>"<span>; </span><span>echo</span> "<td>" . <span>$row</span>['password'] . "</td>"<span>; </span><span>echo</span> "</tr>"<span>; } </span><span>echo</span> "</table>"<span>; </span><span>mysql_close</span>(<span>$con</span><span>); </span>?>從伺服器中獲取使用者所有資訊(SQLc
<?<span>php </span><span>$con</span> = <span>mysql_connect</span>("localhost","root",""<span>); </span><span>if</span> (!<span>$con</span><span>) { </span><span>die</span>('Could not connect: ' . <span>mysql_error</span><span>()); } </span><span>mysql_select_db</span>("test", <span>$con</span><span>); </span><span>mysql_query</span>("DELETE FROM user WHERE username = '<span>$_POST</span>[username]'"<span>); </span><span>mysql_close</span>(<span>$con</span><span>); </span>?>
註冊一個新用戶insert.php
<?<span>php </span><span>$con</span> = <span>mysql_connect</span>("localhost:3306","root",""<span>); </span><span>if</span> (!<span>$con</span><span>) { </span><span>die</span>('Could not connect: ' . <span>mysql_error</span><span>()); } </span><span>mysql_select_db</span>("test", <span>$con</span><span>); </span><span>$sql</span> = "<span>INSERT INTO user (username,password) VALUES ('</span><span>$_POST</span>[username]','<span>$_POST</span>[password]')"<span>; </span><span>if</span> (!<span>mysql_query</span>(<span>$sql</span>,<span>$con</span><span>)) { </span><span>die</span>('Error: ' . <span>mysql_error</span><span>()); } </span><span>echo</span> "1 record added"<span>; </span><span>mysql_close</span>(<span>$con</span><span>); </span>?>
修改一個用戶密碼update.php
以上就介紹了用PHP向資料庫中實現簡單的增刪改查(純程式碼,待完善),包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。