[英]How to make simple sql modifications from shell?
I have never made any software for linux, but it would be better for me now. 我从未为Linux制作过任何软件,但现在对我来说会更好。 I would like to write a simple
SQL modification
software that I can run via terminal
and don't need to run php, apache. 我想编写一个简单的
SQL modification
软件,该软件可以run via terminal
运行,而无需运行php,apache。 ( withouth apache
) (没有
withouth apache
)
Could someone convert me this: 有人可以将我转换为:
<?php
$le = mysql_query('SELECT * FROM tbl_table WHERE alfa="0"');
while ($i = mysql_fetch_assoc($le))
{
$le2 = mysql_num_rows('SELECT * FROM tbl_table3 WHERE t1id="'.$i["id"].'"');
if ($le2 > 0)
{
mysql_query('UPDATE tbl_table SET num="'.$le2.'" WHERE id="'.$i["id"].'"');
}
}
?>
Or can anyone give me a tutorial
for how I could write it for a shell command, or something that can be started from terminal? 还是有人可以
give me a tutorial
有关如何为shell命令编写代码或可以从终端启动的内容give me a tutorial
? Or what is the English name of what I'm looking for? 或者我要寻找的英文名字是什么? (linux debian)
(linux debian)
There are many ways to skin a cat, but I'd go with a Python script. 有很多方法可以给猫皮,但我会使用Python脚本。
Since you're running Linux you'll already have Python on the system. 由于您正在运行Linux,因此系统上已经安装了Python。 You'll need to install a MySQL driver such as MySQLdb and then just convert your simple PHP script to Python.
您需要安装MySQL驱动程序(例如MySQLdb),然后将简单的PHP脚本转换为Python。
There's an excellent answer which covers what you'll need to know (and more) here: How do I connect to a MySQL Database in Python? 有一个很好的答案,涵盖了您在这里需要了解(以及更多)的知识: 如何使用Python连接到MySQL数据库? .
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.