[root@kvm3 ~]# mycli -S /var/lib/mysql/mysql.sock -uroot -p123qwe mariadb 10.3.11-MariaDB mycli 1.20.1 Chat: https://gitter.im/dbcli/mycli Mail: https://groups.google.com/forum/#!forum/mycli-users Home: http://mycli.net Thanks to the contributor - spacewander mariadb root@localhost:(none)> use dyw; You are now connected to database "dyw" as user "root" Time: 0.001s mariadb root@localhost:dyw> quit; Goodbye!
mysqli_select_db
選取資料庫 dywphp。
[root@kvm3 ~]# vim /var/www/html/selectdb.php [root@kvm3 ~]# cat /var/www/html/selectdb.php <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = '123qwe'; $conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die(mysqli_connect_error().PHP_EOL); echo 'Connected successfully'.PHP_EOL; mysqli_select_db( $conn, 'dywphp' ) or die('Error: '.mysqli_error($conn).PHP_EOL); echo "Use Database dywphp\n"; mysqli_close($conn); ?>
[root@kvm3 ~]# curl -s http://127.0.0.1/selectdb.php Connected successfully Use Database dywphp
[root@kvm3 ~]# curl -s http://127.0.0.1/selectdb.php Connected successfully Error: Unknown database 'dywphpi'