Connection between python and php databases _ MySQL

Source: Internet
Author: User
Tags php database
Python and php database connection problems

In a few days of fixing the final project, it involves some handling of connection problems between python and php databases.
There are also database-related systems. here is a small summary.

1. python database connection
Mysql: import MySQLdb
Mssql: import pymssql
Here, I would like to mention that pyodbc can also be connected. I do not even know if there is any pdo Library.

2. php database connection
Mysql:
The connection method is too old. pdo, odbc, and mysql are the default connection methods (no extension is required. this is generally used ).
Mssql:
Here we will divide it into Windows and linux, which is very convenient:
Sqlsrv is supported. this is a connection method officially provided by Microsoft. it can be used after most dll files expire, for example:

Http://www.php.net/manual/zh/book.sqlsrv.php

You can find a method in the codeigniter Forum, for example:

Https://github.com/EllisLab/CodeIgniter/tree/develop/system/database/drivers/sqlsrv

Download two files: sqlsrv_driver.php and sqlsrv_result.php.
Then, before the entry file contains the core file, it contains the above two files.
Configuration method:

Http://stackoverflow.com/questions/19460025/how-do-i-connect-codeigniter-to-a-sql-server

PS: This is also the php Standard expansion.
In Windows, we also need to deal with a series of problems that php later versions do not support mssql. In other words, php6 only supports pdo connections.
Before that, you can use pdo and odbc, or if the server enables the mssql module, you can directly use mssql_connect, but you still need to change the extension configuration in php. ini.

In linux:
I don't want to mention it. it's all broken.
Freetds is an important part of mssql connection in linux. it is essential for linux to connect to mssql. Mssql is derived from sybase. some buddies have developed some connection libraries in sybase linux. These connection libraries also support mssql,
When I use 0.9 (0.8 is also acceptable), the configuration version needs to be set to 8.0 at this time. I will not elaborate on the specific version. if you read more information, you will be surprised.
After freetds is installed (you can download the installation package or install it from yum or apt-get sources ),
Here is a download link: http://blog.csdn.net/kunp/article/details/387013

Then I chose mssql_connect, pdo, or odbc. now I have found these methods. What makes us so sad is that these methods all seem to have to be re-compiled with php and re-compiled with the environment configurations, because I did not find the mssql directory in the ext directory under the php source code installation directory that he said for a long time, and then go to configure, so this path passes away, which requires the phpize compilation step, also pass out. The perl environment of the monks has encountered problems, and the execution of the errors is always related (everyone who understands what's going on is welcome to speak out, even though it is dizzy ). So it means that the php extension connection library file **. so cannot be generated at all, nor can it be used to change the extension configuration path in php. ini.
What should we do? Kiyou told me a way to let me not install Extensions. I directly used php-mssql and centos6 and yum. I did not have an installation package, and I was directly lost with a face:

Https://gist.github.com/shf/2052432

In this way, I installed php-mssql (proxy required), yum installed php-odbc, and then I connected it to mssql. I don't know what's going on. this problem can be solved, I guess other configurations are required. I am confused about what is happening with me ..

3. about enabling remote SQL
As you know, to allow access from external servers, sqlserver must enable remote access and enable 1433.

Http://www.360doc.com/content/13/0525/23/19147_288191810.shtml

This article covers a wide range of topics, but even Port 1433 is not enabled. telnet xx. xx. xx 1433 is not available.

What to do, such:

Http://hi.baidu.com/daheshuiman/item/6dad61982dd267895814615d

Enable and activate Port 1433.
Remember that SQL-server browser must be enabled.
On the Internet, it is said that sqlserver2005 versions earlier than 0.8 need to be patched, that is, at least patch sp3 or above.
PS: Here, I mentioned that the SQL-server browser is not opened and the buttons are dimmed. Therefore, you need to hook all the attributes to the activity.
After it is enabled, you can usually see 1433 telnet connections. During external connection, ip addresses can be directly used online, and the sqlserver instance name must be added, which may not be obvious.

Two additional references are attached:

Http://www.bitsCN.com/database/201304/204867.html

Http://wenwen.sogou.com/z/q410734670.htm

Finally, in the linux environment, mssql cannot be connected, so I had to leave and connect to mysql. However, the original data is stored in mssql, so I need to transfer the data:

Https://github.com/Nick011/MSSQL-to-MySQL/blob/master/convert_db.py

Here we can see that after the cursor is enabled in both databases, it is only commit () after the insert operation is performed. but note that at the end of the process, commit is required for each loop,
This indicates that only one connection is established. Okay, it seems like this is weak ..

Finally, what I mentioned above is rough, not my own will !!! This is because the old man crashes during the experiment, and all the data references are lost. most of the above are separated by memory,
Please do not hesitate to inform us. thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.