📄 dbconnect.txt.html
字号:
<html>
<head>
<title>dbConnect.txt</title>
</head>
<body>
<ol>
<li>Make a copy of the <tt>execsql.cpp</tt> program from Section 28.4.3.
Examine the call to the <tt>mysql_real_connect</tt> function inside the
<tt>main</tt> function:
<blockquote><tt>
if (mysql_real_connect(connection, NULL, NULL, NULL,<br>
"bigcpp", NULL, 0, NULL) == NULL)
</tt></blockquote>
<p>If you need to connect to a remote database or a database with multiple
users, change the first three <tt>NULL</tt> arguments to strings denoting
the host server, the database user name, and the password</p>
</li>
<li>Locate the directories for the header file <tt>mysql.h</tt> and the
<tt>mysqlclient</tt> library files. They should be in the <tt>include</tt>
and <tt>lib</tt> 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
<tt>execsql</tt> program. For example, on Linux, you use the command
<blockquote><tt>
g++ -o execsql -I /usr/local/mysql/include execsql.cpp<br>
-L /usr/local/mysql/lib -lmysqlclient -lz
</tt></blockquote>
</li>
<li>Locate the file <tt>test.sql</tt> 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
<blockquote><tt>
execsql < test.sql
</tt></blockquote>
<p>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.
<p>If your program doesn't work, there are several possible causes.
<ul>
<li>If the <tt>execsql</tt> program didn't compile, check the settings
for the header files and the libraries. Make sure that <tt>mysql.h</tt>
and the <tt>mysqlclient</tt> library are included</li>
<li>If the program starts and does nothing, check that you invoked it
correctly, as <tt>execsql < test.sql</tt></li>
<li>If the program exits with an error message, check that you started
the database before running the <tt>execsql</tt> program</li>
<li>Check that you created the <tt>bigcpp</tt> database and gave at least
one database user the right to access it</li>
<li>If you left the <tt>mysql_real_connect</tt> arguments as
<tt>NULL</tt>, check that the user running the program has the right to
access the database</li>
</ul>
</li>
</ol>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -