我正在尝试使用Codeigniter框架连接到PostgreSQL.现在在我的database.php中
我有以下代码:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'postgres',
'password' => '',
'database' => 'fmsdb',
'dbdriver' => 'postgre',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Run Code Online (Sandbox Code Playgroud)
但是当我在localhost中运行我的站点时,我得到以下数据库错误:
遇到PHP错误
严重性:警告
消息:pg_connect():无法连接到PostgreSQL服务器:无法连接到服务器:权限被拒绝服务器是否在主机"localhost"(:: 1)上运行并接受端口5432上的TCP/IP连接?无法连接到服务器:权限被拒绝服务器是否在主机"localhost"(127.0.0.1)上运行并接受端口5432上的TCP/IP连接?
文件名:postgre/postgre_driver.php
行号:154
我尝试将它放在我的PostgreSQL.conf文件中: …
您好我正在尝试 在我的Codeigniter应用程序中使用GitHUB中的PHPMailer库.
我下载了代码并在我的application\library文件夹中解压缩.所以我有一个名为vendor的文件夹,里面有PHPMailer的源代码.
现在我创建了一个名为的文件Bizmailer_Controller.php.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
*
*/
class Bizmailer_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
require "vendor\phpmailer\phpmailer\PHPMailerAutoload";
$this->Bizmailer = new PHPMailer();
//Set the required config parameters
$this->Bizmailer->isSMTP(); // Set mailer to use SMTP
$this->Bizmailer->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$this->Bizmailer->SMTPAuth = true; // Enable SMTP authentication
$this->Bizmailer->Username = 'user@example.com'; // SMTP username
$this->Bizmailer->Password = 'secret'; // SMTP password …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PHPMYADMIN将users表导出为CSV格式,但我只获取记录而不是coloumn名称.那怎么办?我正在尝试导入CSV,但它需要coloumn名称,所以我想有一个具有列名称的csv!
当我编辑用户并保存它时,它会在数据库中保存空白.它保存所有其他字段,但是对于密码我每次编辑用户时都必须手动添加密码.
这是我的编辑方法::
if ($id)
{
$this->data['user'] = $this->user_m->get_emp($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
$rules = $this->user_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE)
{
$data = $this->user_m->array_from_post(array('emp_id','name','last_name','email','password','phone','gender','designation','user_type','blood_group','date_birth','status','address'));
$data['password'] = $this->user_m->hash($data['password']);
$id = $this->session->userdata('id');
$this->user_m->save($data, $id);
redirect('admin/user/index');
}
}
// Load the view
$this->data['subview'] = 'employee/profile/edit';
$this->load->view('employee/_layout_main', $this->data);
Run Code Online (Sandbox Code Playgroud)
这是我的HASH方法:
public function hash ($string)
{
return hash('sha512', $string . config_item('encryption_key'));
}
Run Code Online (Sandbox Code Playgroud)
现在我想要当我编辑用户并且我不更改他的密码我不希望密码更新为空白而是保持最后插入的密码.
但我的代码生成此查询:
UPDATE `users` SET `emp_id` = '21', `name` = …Run Code Online (Sandbox Code Playgroud) 我想在我的 HTTP 标头中发送 json 数据。
我使用的是 Codeigniter PHP,所以我在我的控制器中做了这个:
header('Content-Type: application/json');'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
$request = array(
'request' => $_GET['request'],
'device_id' => $_GET['device_id'],
'launch_date'=> $_GET['launch_date'],
'allowed_hours'=>$_GET['allowed_hours'],
'site_id'=>$_GET['site_id'],
'product'=>$_GET['product'],
'software_version'=>$_GET['software_version'],
'platform_os'=>$_GET['platform_os'],
'platform'=>$_GET['platform'],
'platform_model'=>$_GET['platform_model']
);
$response = array(
'response_code' =>200 ,
'device_id'=>$_GET['device_id'],
'allowed_hours'=>$_GET['allowed_hours'],
'product'=>'mlc',
'prov_ur'=>NULL
);
header('Content-Type: application/json');
echo json_encode( $response );
Run Code Online (Sandbox Code Playgroud)
但是当我打印我的标题时,我得到
遇到 PHP 错误严重性:注意
消息:未定义索引:请求
文件名:admin/license.php
行号:22
遇到 PHP 错误严重性:注意
消息:未定义索引:allowed_hours
文件名:admin/license.php
行号:25
遇到 PHP 错误严重性:注意
消息:未定义索引:allowed_hours
文件名:admin/license.php
行号:40
{"response_code":200,"device_id":"70D0D01FBAD2","allowed_hours":null,"product":"mlc","prov_ur":null}array(10) { ["Host"]=> string(14) ) "192.168.50.123" ["Connection"]=>
string(10) "keep-alive" ["Cache-Control"]=> string(9) …
我使用带有codeigniter的bootstrap导航栏作为后端.
现在在我的应用程序中,我想将<li>类动态更改为每个页面.
所以我知道我现在在哪个页面上.
以下是我的代码:
<ul class="nav navbar-nav">
<li class="active"><a href="<?php echo site_url('admin/dashboard'); ?>">Dashboard</a></li>
<li><a href="<?php echo site_url('admin/company');?>">Company</a></li>
<li><a href="<?php echo site_url('admin/user');?>">Users Management</a></li>
<li><a href="<?php echo site_url('admin/key');?>">Key Management</a></li>
<li><a href="<?php echo site_url('admin/activation');?>">Activated Devices</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
Run Code Online (Sandbox Code Playgroud) 我想学习如何使用MYSQL TRANSACTIONS.
我有用例,我有两张桌子.让我们说Table1和Table2.现在我在Table1中插入一些数据,然后insert id我从该表中获取,我想将其插入表2中.
如果在Table1中成功插入值,并且在插入Table2值期间发生任何错误,我也想删除Table1中的值,因为我的Table2的查询不成功.
我只想了解如何使用Codeigniter完成此操作.如何根据需要进行COMMIT或ROLLBACK.
请帮我一些示例代码来理解.
更新
我还提到了Codeigniter UserGuide.但我没理解这个概念是Running Transactions manually什么意思?如上所述,我想做一些像触发器这样是自动的,我的意思是如果我的查询失败,我希望它使用Codeigniter进行ROLLBACK.
码:
$this->db->trans_begin();
$data = $this->Product_m->array_from_post(array('name','description'));
$this->Product_m->save($data,$id);
$pid = $this->db->insert_id();
$num_of_license = $_POST['license'];
$this->Product_m->create_product($pid,$num_of_license);
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
}
Run Code Online (Sandbox Code Playgroud)
现在在这种情况下我尝试这样做:
此语句$this->Product_m->create_product($pid,$num_of_license);基于先前的save()方法插入数据,现在假设在create_product()方法期间发生了一些错误.然后我想回滚.我想删除save()方法所做的记录.
我想知道我有数据的最后日期.所以我想在我的列date_data中打印最后一个日期.
在模型中:
public function last_record()
{
$query = $this->db->select('LAST(date_data)');
$this->db->from('date_data');
return $query;
}
Run Code Online (Sandbox Code Playgroud)
在控制器中:
$last_data = $this->attendance_m->last_record();
var_dump($last_data);
Run Code Online (Sandbox Code Playgroud)
但我没有得到理想的结果
我收到此错误:
未捕获的类型错误:无法设置未定义的属性“_DT_CellIndex”
我在网上搜了一下,发现通常是th的计数与td的计数不匹配时发生。
但我不认为这是造成问题的原因。见下表定义:
$(document).ready(function() {
$('#chat').DataTable({
responsive: true,
"bLengthChange": false,
});
} );Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<link href="//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet"/>
<table class="table table-striped table-bordered" id="chat">
<thead>
<tr>
<th>From</th>
<th>To</th>
<th>Message</th>
<th>Time of Messgae</th>
</tr>
</thead>
<tbody>
<tr>
<td>jhon</td>
<td>rylie</td>
<td>
<message xmlns:cli="jabber:client" to="rylie__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="jhon_1523607791051" from="jhon__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
<body>Hey Rylie</body>
<request xmlns="urn:xmpp:receipts"></request>
</message>
</td>
<td>13-04-18 08:23:11</td>
</tr>
<tr>
</tr>
<tr>
<td>rylie</td>
<td>jhon</td>
<td>
<message xmlns:cli="jabber:client" to="jhon__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="rylie_1523607808352" from="rylie__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
<body>Hey Jhon</body>
<request xmlns="urn:xmpp:receipts"></request>
</message>
</td> …Run Code Online (Sandbox Code Playgroud)我是 codeigniter 的新手。我有一个项目,管理员将余额分配给其经销商。现在我想在 html 中创建一个按钮,为管理员提供界面以增加按钮单击时的余额。当他增加它时,数据库中的值也应该更新。也许这很简单,但我做不到!我想我应该使用 ajax 或 Jquery 来实现这个
下面是我的视图代码:(除了余额输入之外还想添加增量和减量按钮)
<?php echo validation_errors(); ?>
<?php echo form_open(); ?>
<table class="table">
<tr>
<td>SIP Username</td>
<td><?php echo form_input('sip_username', set_value('sip_username', $user->sip_username)); ?></td>
</tr>
<tr>
<td>SIP Password</td>
<td><?php echo form_input('sip_password', set_value('sip_password', $user->sip_password)); ?></td>
</tr>
<tr>
<td>Key</td>
<td><?php echo form_input('key', set_value('key', $user->key), 'readonly'); ?></td>
</tr>
<tr>
<td>Allocation Block</td>
<td><?php echo form_input('allocation_block', set_value('allocation_block', $user->allocation_block)); ?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo form_input('name', set_value('name', $user->name)); ?></td>
</tr>
<tr>
<td>Reseller Email</td>
<td><?php echo form_input('email', set_value('email', $user->email)); ?></td>
</tr>
<tr> …Run Code Online (Sandbox Code Playgroud) php ×8
codeigniter ×7
mysql ×3
html ×2
css ×1
datatable ×1
datatables ×1
http-headers ×1
javascript ×1
jquery ×1
phpmailer ×1
phpmyadmin ×1
phpwebsocket ×1
postgresql ×1
sql ×1
tcp ×1
transactions ×1