⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbconnect.txt

📁 《Big C++ 》Third Edition电子书和代码全集-Part1
💻 TXT
字号:

1. Make a copy of the execsql.cpp program from Section 28.4.3. Examine the call
to the mysql_real_connect function inside the main function:

	if (mysql_real_connect(connection, NULL, NULL, NULL,
			"bigcpp", NULL, 0, NULL) == NULL)

If you need to connect to a remote database or a database with multiple users,
change the first three NULL arguments to strings denoting the host server, the
database user name, and the password.

2. Locate the directories for the header file mysql.h and the mysqlclient
library files. They should be in the include and lib subdirectories of the
MySQL installation directory. Add the path of the header file directory to
your compiler's header file directories. Add the library to your compiler's
libraries. Compile the execsql program. For example, on Linux, you use the
command

	g++ -o execsql -I /usr/local/mysql/include execsql.cpp
		-L /usr/local/mysql/lib -lmysqlclient -lz

3. Locate the file test.sql that contains the same SQL instructions as the
database test in Step 6 above. It is included with the code distribution for
this book. Then run the command

	execsql < test.sql

The program should print Romeo, the same output as with the first database
test. If this test passes, then you are ready to run the programs of the next
section.

	If your program doesn't work, there are several possible causes.

	If the execsql program didn't compile, check the settings for the header
	files and the libraries. Make sure that mysql.h and the mysqlclient library
	are included.

	If the program starts and does nothing, check that you invoked it correctly,
	as execsql < test.sql.

	If the program exits with an error message, check that you started the
	database before running the execsql program.

	Check that you created the bigcpp database and gave at least one database
	user the right to access it.

	If you left the mysql_real_connect arguments as NULL, check that the user
	running the program has the right to access the database.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -